package com.java.jvm.demo.chapter01;

/**
 * @author wangning
 * @create 2021-10-12 21:15
 */
public class ClassLoaderTest {
	public static void main(String[] args) {
		//获取系统类加载器
		ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
		System.out.println("systemClassLoader = " + systemClassLoader);

		//获取器上层加载器：扩展类加载器,加载器直接是包含关系
		ClassLoader extClassLoader = systemClassLoader.getParent();
		System.out.println("extClassLoader = " + extClassLoader);

		//试图在获取上层类加载器，结果发现获取不到，是个null，获取不到引导类加载器
		ClassLoader bootstrapClassLoader = extClassLoader.getParent();
		System.out.println("bootstrapClassLoader = " + bootstrapClassLoader);//null

		//对于用户自定义类来说：默认使用的是系统类加载器
		ClassLoader classLoaderTest = ClassLoaderTest.class.getClassLoader();
		System.out.println("classLoaderTest = " + classLoaderTest);

		//String类使用引导类加载器加载的，Java的核心库都是使用引导类加载器加载的
		ClassLoader classLoader = String.class.getClassLoader();
		System.out.println("classLoader = " + classLoader);
	}
}
